#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=1e5+5;
long long n,m,L;
long long V;
long long p[MAXN];
struct node{
    long long d,v,add;
}a[MAXN];
struct node1{
    long long l,r;
}b[MAXN];
long long pos[MAXN],st[MAXN];
long long dist(long long v,long long add,long long len){
    return v*v+2*add*len;
}
bool cmp(node1 x,node1 y){
    if(x.l==y.l){
        return x.r<y.r;
    }
    return x.l<y.l;
}
void solve(){
    cin>>n>>m>>L>>V;
    for(int i=1;i<=n;i++){
        scanf("%lld%lld%lld",&a[i].d,&a[i].v,&a[i].add);
    }
    for(int i=1;i<=m;i++){
        scanf("%lld",&p[i]);
    }
    for(int i=1;i<=n;i++){
        int l=1,r=m,ans=-1;
        while(l<=r){
            int mid=l+r>>1;
            if(p[mid]<a[i].d){
                l=mid+1;
            }else{
                ans=mid;
                r=mid-1;
            }
        }
        if(!(ans>=1&&ans<=m)){
            st[i]=-1;
            continue;
        }
        st[i]=ans;
    }
    long long ret=0;
    for(int i=1;i<=n;i++){
        int l=1,r=m,ans=-1;
        if(a[i].add==0){
            ret+=(a[i].v>V&&a[i].d<=p[m]);
            if(a[i].v<=V||a[i].d>p[m]){
                pos[i]=-1;
            }
        }else if(a[i].add>0){
            if(st[i]==-1){
                pos[i]=-1;
                continue;
            }
            l=st[i];
            while(l<=r){
                int mid=l+r>>1;
                if(dist(a[i].v,a[i].add,p[mid]-a[i].d)>V*V){
                    ans=mid;
                    r=mid-1;
                }else{
                    l=mid+1;
                }
            }
            pos[i]=ans;
            if(ans!=-1){
                ret++;
            }
        }else{
            if(st[i]==-1){
                pos[i]=-1;
                continue;
            }
            l=st[i];
            while(l<=r){
                int mid=l+r>>1;
                if(dist(a[i].v,a[i].add,p[mid]-a[i].d)<=0){
                    r=mid-1;
                    continue;
                }
                if(dist(a[i].v,a[i].add,p[mid]-a[i].d)>V*V){
                    ans=mid;
                    l=mid+1;
                }else{
                    r=mid-1;
                }
            }
            pos[i]=ans;
            if(ans!=-1){
                ret++;
            }
        }
    }
    printf("%lld ",ret);
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(a[i].add==0){
            if(a[i].v<=V||a[i].d>p[m]){
                continue;
            }
            b[++cnt].l=st[i];
            b[cnt].r=m;
        }else if(a[i].add>0){
            if(pos[i]==-1){
                continue;
            }
            b[++cnt].l=pos[i];
            b[cnt].r=m;
        }else{
            if(pos[i]==-1){
                continue;
            }
            b[++cnt].l=st[i];
            b[cnt].r=pos[i];
        }
    }
    sort(b+1,b+cnt+1,cmp);
    long long ans=0,last=-999999;
    for(int i=1;i<=cnt;i++){
        if(b[i].l>last){
            last=b[i].r;
            ans++;
        }
        last=min(last,b[i].r);
    }
    printf("%lld\n",m-ans);
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
